package com.chengliang.bbs.service.impl;

import com.chengliang.bbs.entry.UserAuths;
import com.chengliang.bbs.mapper.UserAuthsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * 登录验证处理
 * @author chengliang
 */
@Service
@Slf4j
public class MyUserDetailsService implements UserDetailsService {

    @Autowired
    private UserAuthsMapper userAuthsMapper;

    @Override
    public UserDetails loadUserByUsername(String loginName) throws UsernameNotFoundException {
        log.info("{}尝试登陆",loginName);
        UserAuths userAuths = userAuthsMapper.selectUserByUserIdentifier(loginName);
        if(userAuths == null){
            throw new UsernameNotFoundException("用户名不存在");
        }
        return userAuths;
    }

}
